import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter01/global.dart';

import 'package:flutter01/page/animation/animation_page.dart';
import 'package:flutter01/pub/pub_page.dart';
import 'package:flutter01/stateManagement/provider/provider_page.dart';
import 'package:flutter01/stateManagement/state_managemen_page.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:provider/provider.dart' as provider;
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'page/widget_page.dart';

void main() {
  runApp(ProviderScope(child: const MyApp()));
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(360, 690),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: () => provider.MultiProvider(
        providers: [
          provider.ChangeNotifierProvider(create: (_) => AnimationModel()),
          provider.ChangeNotifierProvider(create: (_) => Model1()),
        ],
        child: MaterialApp(
          debugShowCheckedModeBanner: false,
          builder: (context, widget) {
            print(Global.screenOrientation = MediaQuery.of(context).size.width > MediaQuery.of(context).size.height ? "LANDSCAPE" : "PORTRAIT");
            ScreenUtil.setContext(context);
            return MediaQuery(
              data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
              child: widget!,
            );
          },
          theme: ThemeData(
            textTheme: TextTheme(
                //要支持下面这个需要使用第一种初始化方式
                button: TextStyle(fontSize: 45.sp)),
          ),
          home: const MyHomePage(
            title: 'Helo',
          ),
          // home: const Name(),
        ),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _currentIndex = 0;
  List<Widget> list = [
    StateManagemenPage(),
    WidgetPage(),
    PubPage(),
    AnimationPage(),
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(40.h),
        child: AppBar(
          title: Text(
            widget.title,
            style: TextStyle(fontSize: 25.sp, color: Colors.black),
          ),
          backgroundColor: Colors.white,
          centerTitle: true,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(topLeft: Radius.circular(20), bottomRight: Radius.circular(20), topRight: Radius.circular(5), bottomLeft: Radius.circular(5)),
          ),
          actions: [
            IconButton(icon: Icon(Icons.star, color: Colors.red), tooltip: 'like', onPressed: () {}),
          ],
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home, size: 30), label: "StateManagemen"),
          BottomNavigationBarItem(icon: Icon(Icons.blur_circular, size: 30), label: "WidgetPage"),
          BottomNavigationBarItem(icon: Icon(Icons.sailing_outlined, size: 30), label: "PubExample"),
          BottomNavigationBarItem(icon: Icon(Icons.abc_rounded, size: 30), label: "Tmp"),
        ],
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        currentIndex: this._currentIndex,
        type: BottomNavigationBarType.fixed,
      ),
      body: list[_currentIndex],
      floatingActionButton: FloatingActionButton(
        backgroundColor: Colors.red,
        onPressed: () {
          BrnToast.show("共找到10932个结果", context, duration: BrnToast.LENGTH_LONG);
          // Fluttertoast.showToast(说
          //   msg: "你好帅哥",
          //   toastLength: Toast.LENGTH_LONG,
          //   gravity: ToastGravity.CENTER,
          //   timeInSecForIosWeb: 1,
          //   backgroundColor: Colors.red,
          //   textColor: Colors.white,
          //   fontSize: 16.0,
          // );
        },
        tooltip: 'Good!',
        child: const Icon(Icons.add, size: 36),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}
